import * as echarts from 'echarts'



function getYaxisSeries(charts) {
  const color = ['rgba(23, 255, 243', 'rgba(255,100,97']
  const lineY = []

  for (let i = 0; i < charts.names.length; i++) {
    let x = i
    if (x > color.length - 1) {
      x = color.length - 1
    }
    let data = {
      // name: charts.names[i],
      type: 'line',
      color: color[x] + ')',
      smooth: true,
      label: {
        show: true,
        color: '#fff',
        position: "top",
        formatter: function (p) {
          return p.value > 0 ? (p.value) : '0';
        }
      },
      areaStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(
            0,
            0,
            0,
            1,
            [
              {
                offset: 0,
                color: color[x] + ', 0.3)'
              },
              {
                offset: 0.8,
                color: color[x] + ', 0)'
              }
            ],
            false
          ),
          shadowColor: 'rgba(0, 0, 0, 0.1)',
          shadowBlur: 10
        }
      },
      symbol: 'circle',
      symbolSize: 5,
      data: charts.value[i]
    }
    lineY.push(data)
  }

  return lineY
}


const option = {
  tooltip: {
    trigger: 'axis'
  },
  legend: {
    // data: ['当前'],
    textStyle: {
      fontSize: 12,
      // legend字体颜色
      color: 'rgb(0,253,255,0.6)'
    },
    right: '4%'
  },
  grid: {
    top: '14%',
    left: '4%',
    right: '10%',
    bottom: '12%',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: [],

    axisLabel: {
      textStyle: {
        // 横坐标日期字体颜色
        color: 'rgb(0,253,255,0.6)'
      },
      formatter: function (params) {
        return params.split(' ')[0]
      }
    }
  },
  yAxis: {
    // name: charts.unit,
    type: 'value',
    axisLabel: {
      formatter: '{value}',
      textStyle: {
        // 横坐标 刻度字体颜色
        color: '#c9cdfe'
      }
    },
    min: 0,
    minInterval: 10,
    splitLine: {
      lineStyle: {
        color: 'rgba(13, 55, 154, 0.6)'
      }
    },
    axisLine: {
      lineStyle: {
        color: 'rgba(13, 55, 154, 0.6)'
      }
    }
  },
  series: []
}

export default ({ xaxis, yaxis }) => {

  const charts = {
    names: ['当前'],
    value: [yaxis]
  }
  option.series = getYaxisSeries(charts)
  option.xAxis.data = xaxis
  return {
    ...option,

  }

}
